﻿
//***********************************************************************
// * Module:   MsjHzLhpsbHandler
// * 作者:  XWG
// * Modified: 2013-05-29
// * Purpose: Definition of the Class MsjHzLhpsbHandler 业务逻辑处理Handler类
// ***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
using XWG.Framework.Query;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using XWG.Framework.MSException;
using XWG.Framework.AuthUtility;
using XWG.Framework.AuthEntity;
using XWG.Framework.AuthSPConst;
using XWG.Framework.AuthBLL;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.JWBSTSPConst;
using XWG.JWBST.JWBSTBLL;

namespace JWBSTAPP.AjaxServer
{
    /// <summary>
    /// MsjHzLhpsbHandler 的摘要说明
    /// </summary>
    public class MsjHzLhpsbHandler : JWBSTAPP.CommonClass.HttpHandlerBase, System.Web.SessionState.IRequiresSessionState
    {
      
        #region 添加记录
      /// <summary>
      /// 添加记录
      /// </summary>
      protected void AddRecord()
        {
             HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            try
            {           
            MsjHzLhpsb mMsjHzLhpsb = new MsjHzLhpsb();
            mMsjHzLhpsb.Sqid = Guid.NewGuid().ToString(); //主键
                 mMsjHzLhpsb.Kfsmc = context.Request.Form["texKfsmc"]; //开发商名称
                 mMsjHzLhpsb.Njxqmc = context.Request.Form["texNjxqmc"]; //拟建小区名称
                 mMsjHzLhpsb.Njxqdz = context.Request.Form["texNjxqdz"]; //拟建小区地址(标准名称)
                 mMsjHzLhpsb.Szfjpcs = context.Request.Form["texSzfjpcs"]; //所在分局派出所(字典)
                 mMsjHzLhpsb.Lxr = context.Request.Form["texLxr"]; //联系人
                 mMsjHzLhpsb.Lxfs = context.Request.Form["texLxfs"]; //联系方式
                 mMsjHzLhpsb.Tgxgzl = context.Request.Form["texTgxgzl"]; //提供相关资料
                 mMsjHzLhpsb.Gajgfkqk = context.Request.Form["texGajgfkqk"]; //公安机关反馈情况
                 mMsjHzLhpsb.Bz = context.Request.Form["texBz"]; //备注
                 mMsjHzLhpsb.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                 mMsjHzLhpsb.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                 mMsjHzLhpsb.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                 mMsjHzLhpsb.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                 mMsjHzLhpsb.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                 mMsjHzLhpsb.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                 mMsjHzLhpsb.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                 mMsjHzLhpsb.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）
            
            mResultModel = MsjHzLhpsbBLL.Insert(mMsjHzLhpsb,context.Session["UserID"], true); //新建操作
            context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion
        
        #region 删除记录
      /// <summary>
      /// 删除记录
      /// </summary>
       protected void DeleteRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //声明返回类型
            string paramKey = context.Request.Params["id"];
            try
            {
              if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return ;
                }
                
                MsjHzLhpsb mMsjHzLhpsb = new MsjHzLhpsb(); 
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mResultModel = MsjHzLhpsbBLL.Delete(paramKey, context.Session["UserID"], true); //删除对应的信息
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel));  //序列化后返回
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty); //写入异常日志
                mResultModel.ErrorCode = -9999; //-9999代码是系统异常通用代码
                mResultModel.ISSucceed = false; //行为执行失败
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }            
        } 
        #endregion
     
        #region 修改记录
      /// <summary>
      /// 修改记录
      /// </summary>
      protected void EditRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
           MsjHzLhpsb mMsjHzLhpsb = new MsjHzLhpsb();

            string paramKey = context.Request.Params["id"];
            try
            {
                
                if(string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return ;
                }
                   mMsjHzLhpsb = MsjHzLhpsbBLL.Load(paramKey); //根据键值获取实体信息
                    if (mMsjHzLhpsb != null)
                    {
                 mMsjHzLhpsb.Kfsmc = context.Request.Form["texKfsmc"]; //开发商名称
                 mMsjHzLhpsb.Njxqmc = context.Request.Form["texNjxqmc"]; //拟建小区名称
                 mMsjHzLhpsb.Njxqdz = context.Request.Form["texNjxqdz"]; //拟建小区地址(标准名称)
                 mMsjHzLhpsb.Szfjpcs = context.Request.Form["texSzfjpcs"]; //所在分局派出所(字典)
                 mMsjHzLhpsb.Lxr = context.Request.Form["texLxr"]; //联系人
                 mMsjHzLhpsb.Lxfs = context.Request.Form["texLxfs"]; //联系方式
                 mMsjHzLhpsb.Tgxgzl = context.Request.Form["texTgxgzl"]; //提供相关资料
                 mMsjHzLhpsb.Gajgfkqk = context.Request.Form["texGajgfkqk"]; //公安机关反馈情况
                 mMsjHzLhpsb.Bz = context.Request.Form["texBz"]; //备注
                 mMsjHzLhpsb.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                 mMsjHzLhpsb.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                 mMsjHzLhpsb.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                 mMsjHzLhpsb.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                 mMsjHzLhpsb.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                 mMsjHzLhpsb.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                 mMsjHzLhpsb.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                 mMsjHzLhpsb.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）
            
            mResultModel = MsjHzLhpsbBLL.Update(mMsjHzLhpsb,context.Session["UserID"], true); //新建操作
                 }
                else
                 {
                mResultModel.ErrorCode = -9990; //没有获取所需的信息，信息可能已被删除
                mResultModel.ISSucceed = false;               
                 }
                
            context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }    
        #endregion 
        
        #region 获取实体记录
      /// <summary>
      /// 获取实体记录
      /// </summary>
        protected void GetModel()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
             ResultModel mResultModel = new ResultModel(); //初始化返回类型
            string paramKey = context.Request.Params["id"];
            string json = string.Empty;
            try
            {
                MsjHzLhpsb mMsjHzLhpsb = new MsjHzLhpsb(); //声明实体
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mMsjHzLhpsb = MsjHzLhpsbBLL.Load(paramKey); //根据键值获取管理员
                    if (mMsjHzLhpsb != null)
                    {
                        json = JsonConvert.SerializeObject(mMsjHzLhpsb);
                    }
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9990;
                mResultModel.ISSucceed = false;
                json = JsonConvert.SerializeObject(mResultModel);
            }
            
            context.Response.Write(json);
        }
        #endregion
      
        #region 获取数据
        /// <summary>
      /// 获取数据记录
      /// </summary>
       protected void QueryRecord()
        {
            TableMessage tm = new TableMessage();
            HearderMessage hm = new HearderMessage();
            List<HearderMessage> list = new List<HearderMessage>();
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            string pageSize = context.Request.Form["pageSize"];
            string pageIndex = context.Request.Form["pageIndex"];
            if (String.IsNullOrEmpty(pageSize) || String.IsNullOrEmpty(pageIndex) || !AnyString.IsNumeric(pageSize) || !AnyString.IsNumeric(pageIndex))
            { 
                return;
            }
            
            DataTable dtMsjHzLhpsb = new DataTable();
            int intPageSize = Convert.ToInt32(pageSize);
            int intPageIndex = Convert.ToInt32(pageIndex);
            QueryByPage q=new QueryByPage();
            QueryInfo qInfo=new QueryInfo();
            dtMsjHzLhpsb = q.GetRecordByPage("*", string.Empty, string.Empty, intPageSize, intPageIndex,  MsjHzLhpsbConst.TableName, MsjHzLhpsbConst.FieldKey, string.Empty).Tables[0];
            if (dtMsjHzLhpsb != null && dtMsjHzLhpsb.Rows.Count > 0)
             {
                 for (int i = 0; i < dtMsjHzLhpsb.Columns.Count; i++)
                 {
                     hm = new HearderMessage();
                     hm.name = dtMsjHzLhpsb.Columns[i].Caption;
                     list.Add(hm);
                 }
                
                 tm.Header = list;
                 tm.data = dtMsjHzLhpsb;
                 tm.totalCount = Convert.ToString((int)q.RowCount);
             }
            
            string json = JsonConvert.SerializeObject(tm);
            context.Response.Write(json);
        }
       
       protected void QueryGtRecord()
        {
           HttpContext context = HttpContext.Current;
           context.Response.ContentType = "text/plain";

           QueryInfo info = new QueryInfo();
           QueryByPage page = new QueryByPage();
           info.FieldKey = MsjHzLhpsbConst.FieldKey;
           info.PageIndex = 1;
           info.PageSize = 0;
           info.QTableName = MsjHzLhpsbConst.TableName;
           info.SelectFields = "*";

           info.Where = string.Empty;
           DataSet ds = page.GetRecordByPage(info);
           DataTable table = new DataTable();
        
           if (ds.Tables.Count > 0)
           {
               table = page.GetRecordByPage(info).Tables[0];
           }
           string json = JsonConvert.SerializeObject(table);
           context.Response.Write(json);
        }
         #endregion           
}
}
 
 
